package wiki.kaizen.cloud.security.session.util;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.session.Session;
import org.apache.shiro.util.StringUtils;
import wiki.kaizen.cloud.security.session.SecurityGlobalConst;

public class ISecurityUtil {
    /**
     * 获取session 里的唯一key
     * */
    public static String key(Session session){
        String key = (String) session.getAttribute(SecurityGlobalConst.KEY);
        if (!StringUtils.hasText(key)){
            throw new RuntimeException("Session 未设置属性:"+SecurityGlobalConst.KEY);
        }
        return key;
    }
    /*
     * 加密算法
     * */
    public static String hashAlgorithmName = "MD5";

    /**
     *循环次数
     */
    public static Short hashIterations = 4;

    public static String doHash(String password,String salt){
        return new SimpleHash(hashAlgorithmName,password,salt,hashIterations).toString();
    }
}
